package bx.com.smartcashier.view;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSONArray;
import com.android.volley.AuthFailureError;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import bx.com.smartcashier.R;
import bx.com.smartcashier.activity.CashRegisterSucessedActivity;
import bx.com.smartcashier.config.ServerUrl;
import bx.com.smartcashier.mode.GoodsDetailVO;
import bx.com.smartcashier.mode.GoodsUp;
import bx.com.smartcashier.utils.JsonUtils;

/**
 * 底部弹窗Fragment
 */
public class TransactionFragment extends DialogFragment {
    private RelativeLayout  reZfb,reCancle,reWx,reBank;

    //定义回调接口
    public interface MyListener{
        public int sendValue(int value);
    }
    private MyListener myListener;


    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        //获取实现接口的activity
        myListener = (MyListener) getActivity();//或者myListener=(MainActivity) context;
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // 使用不带Theme的构造器, 获得的dialog边框距离屏幕仍有几毫米的缝隙。
        Dialog dialog = new Dialog(getActivity(), R.style.BottomDialog);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // 设置Content前设定
        dialog.setContentView(R.layout.fragment_transaction);
        dialog.setCanceledOnTouchOutside(true); // 外部点击取消
        // 设置宽度为屏宽, 靠近屏幕底部。
        final Window window = dialog.getWindow();
        window.setWindowAnimations(R.style.AnimBottom);
        final WindowManager.LayoutParams lp = window.getAttributes();
        lp.gravity = Gravity.BOTTOM; // 紧贴底部
        lp.width = WindowManager.LayoutParams.MATCH_PARENT; // 宽度持平
        lp.height = getActivity().getWindowManager().getDefaultDisplay().getHeight() * 3 / 10;
        window.setAttributes(lp);



        reCancle = (RelativeLayout)dialog.findViewById(R.id.re_cancle);//取消
        reZfb=(RelativeLayout)dialog.findViewById(R.id.re_zfb);//全部
        reWx=(RelativeLayout)dialog.findViewById(R.id.rl_wx);//销售详情
        reBank=(RelativeLayout)dialog.findViewById(R.id.rl_bank);//退货详情




        reCancle.setOnClickListener(listener);
        reZfb.setOnClickListener(listener);
        reWx.setOnClickListener(listener);
        reBank.setOnClickListener(listener);

        initDatas();
        return dialog;
    }

    /**
     * 初始化数据
     */
    private void initDatas() {



    }




    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Animation slide_left_to_left = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_left_to_left);
            Animation slide_right_to_left = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_right_to_left);
            Animation slide_left_to_right = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_left_to_right);
            Animation slide_left_to_left_in = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_left_to_left_in);
            switch (view.getId()) {
                case R.id.re_cancle:
                    dismiss();
                    break;
                case R.id.re_zfb://全部
                    myListener.sendValue(0);
                    dismiss();
                    break;

                case R.id.rl_wx://销售详情
                    myListener.sendValue(1);
                    dismiss();
                    break;
                case R.id.rl_bank://退货详情
                    myListener.sendValue(2);
                    dismiss();
                 break;
                default:
                    break;
            }
        }
    };


}

